package com.zrrd.yunchmall.user.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zrrd.yunchmall.user.entity.ResourceCategory;
import com.zrrd.yunchmall.user.service.IResourceCategoryService;
import com.zrrd.yunchmall.util.ResponseResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 资源分类表 前端控制器
 * </p>
 *
 * @author LYY
 * @since 2024-01-15
 */
@RestController
@RequestMapping("/resourceCategory")
public class ResourceCategoryController {
    @Autowired
    private IResourceCategoryService service;

    @GetMapping("/listAll")
    @ApiOperation("查询角色资源")
    public ResponseResult listAll(Integer id){

        return new ResponseResult<>(200,"查询成功!",service.list());
    }
    @PostMapping("/allocResource")
    @ApiOperation("分配角色资源")
    public ResponseResult allocResource(){
        return new ResponseResult<>(200,"查询成功!");
    }

    @PostMapping("/update/{id}")
    @ApiOperation("编辑资源分类")
    public ResponseResult update(@PathVariable("id") Integer id,@RequestBody ResourceCategory resourceCategory){
        UpdateWrapper updateWrapper=new UpdateWrapper<>();
        updateWrapper.eq("id",id);
        return new ResponseResult<>(200,"查询成功!",service.update(resourceCategory,updateWrapper));
    }
    @PostMapping("/delete/{id}")
    @ApiOperation("删除")
    public ResponseResult delete(@PathVariable("id") Integer id){
        return new ResponseResult<>(200,"查询成功!",service.removeById(id));
    }
    @PostMapping("/create")
    @ApiOperation("添加资源")
    public ResponseResult create(@RequestBody ResourceCategory resourceCategory){
        return new ResponseResult<>(200,"查询成功!",service.save(resourceCategory));
    }
}
